/**
 * Copyright 2021 Inc.
 **/
package com.myz.rabbitmq.common.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author maoyz0621 on 2021/6/7
 * @version v1.0
 */
@Configuration
public class TopicExchangeConfig {

    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(RabbitMqConstant.ExchangeEnum.CONTRACT_TOPIC.getCode(), true, false);
    }


    /**
     * 将消息队列2和交换机topic进行绑定,指定队列key
     *
     * @return
     */
    @Bean
    public Binding bindingTopic1(Queue secondQueue) {
        return BindingBuilder.bind(secondQueue)
                .to(topicExchange())
                .with(RabbitMqConstant.RoutingKeyEnum.TOPIC_QUEUE_KEY_1.getCode());
    }

    /**
     * 将消息队列3和交换机topic进行绑定,指定队列key
     *
     * @return
     */
    @Bean
    public Binding bindingTopic2(Queue thirdQueue) {
        return BindingBuilder.bind(thirdQueue)
                .to(topicExchange())
                .with(RabbitMqConstant.RoutingKeyEnum.TOPIC_QUEUE_KEY_2.getCode());
    }
}